#include "util.h"
#include<string>

using namespace std;

namespace util{
	

	StringTokenizer::StringTokenizer(string str,string sep) 
	{ 
		elements = vector<string>();
		index=0; 
		string str1=""; 
		for (unsigned int i=0;i<str.length() && sep.length()==1;i++) 
		{ 
			if(str[i]==sep[0]) 
			{ 
				elements.push_back(str1);
				str1=""; 
			} 
			else 
			{ 
				str1+=str[i]; 
			} 
		} 
		elements.push_back(str1); 
	} 
	// Method is used to fetch the tokens. 

	string StringTokenizer::getNextElement() 
	{ 
		index++; 
		if(index>elements.size()) 
		{ 
			throw string("Index out of Bounds"); 
		} 
		return elements[index-1]; 
	} 
	//method used to fetch the count of tokens from the string 

	int StringTokenizer::countElements() 
	{ 
		return elements.size(); 
	} 

	//fetch the elements at given position 

	string StringTokenizer::elementAt(unsigned int index) 
	{ 
		if(index>=elements.size() ||index<0) 
		{ 
			throw string("Index out of Bounds"); 
		} 
		else 
			return elements[index]; 
	} 

	bool StringTokenizer::hasMoreElements(){
		return index < elements.size();
	}

}